import * as user from '@/api/user.js'
import * as index from '@/api/index.js'
import HomeList from '@/components/homeList/homeList.vue'
export default {
	components: {
		HomeList
	},
	data() {
		return {
			homeList: [], //列表数据
			form: {
				page: 1, //  默认分页 
				type: 1, //  1房源 2求租
			}, //查询条件
			reachBottom: false, //是否继续加载
			List: [],
			title: [{
					name: '房源',
					type: 1
				},
				{
					name: '其他',
					type: 2
				}
			]
		}
	},

	onShow() {
		this.getDialList()
	},
	onLoad(option) {
		// 	let that = this
		// 	uni.$on('form', function(data) {
		// 		that.form = data
		// 		that.getDialList()
		// 	})
	},
	onReachBottom() { //触底加载
		if (this.reachBottom) {
			this.getDialList();
		}
	},
	methods: {
		getDialList() {
			user.getDialList(this.form).then(res => {
				console.log(this.reachBottom);
				if (this.form.page == 1) {
					this.homeList = res.data.data
					this.List = res.data.data
				} else {
					this.homeList = this.homeList.concat(res.data.data);
					this.List = this.homeList.concat(res.data.data);
				}
				this.form.page = res.data.current_page + 1
				//判断 是否是最后一页

				if (res.data.current_page != res.data.last_page) {
					this.reachBottom = true;
				} else {
					this.reachBottom = false;
				}
				if (this.form.type == 1) {
					if (this.homeList.length < 10) {
						this.reachBottom = false;
					}
				} else {
					if (this.List.length < 10) {
						this.reachBottom = false;
					}

				}

			})
		},
		// getList() {
		// 	index.getWantList(this.form).then(res => {
		// 		this.List.push(...res.data.data)
		// 	})
		// },
		indexChange(item) {
			// this.reachBottom = true;
			console.log(this.reachBottom);
			this.form.type = item.type
			this.form.page = 1
			this.homeList = this.List = []
			this.getDialList()

		},
		details(item) {
			this.$tools.navigate(`/pages/home/rentHome/details/details?id=${item.id}`)
		},

	}
}
